package com.qiyuesuo.untils;

import com.qiyuesuo.common.BaseClass;

import java.io.*;

/**
 * 关闭流
 */
public class CloseStreamUntils extends BaseClass {

    public static void closeStream(FileOutputStream fos) {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
                logger.error("关闭FileOutputStream失败" + e.getMessage() + "||" + e.getStackTrace());
            }
        }

    }

    public static void closeStream(OutputStream os, Reader reader, InputStreamReader inputStreamReader, InputStream inputStream) {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                logger.error("关闭OutputStream失败" + e.getMessage() + "||" + e.getStackTrace());
            }
        }
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                logger.error("关闭Reader失败" + e.getMessage() + "||" + e.getStackTrace());
            }
        }
        if (inputStreamReader != null) {
            try {
                inputStreamReader.close();
            } catch (IOException e) {
                logger.error("关闭inputStreamReader失败" + e.getMessage() + "||" + e.getStackTrace());
            }
        }
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                logger.error("关闭inputStream失败" + e.getMessage() + "||" + e.getStackTrace());
            }
        }


    }
}

